package name.zxw.xiaowo.luckycache.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.StringVendorExtension;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

/**
 * swagger配置
 * @author ZhangXinWang
 * @date 2022/5/12 2:36
 * @since https://blog.csdn.net/A2254536570/article/details/121767271
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment) {

        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .build();
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact("张心望", "https://gitee.com/zhangxinwang/blog", "1336789387@qq.com");
        List<VendorExtension> vendorExtensions = new ArrayList<>();
        vendorExtensions.add(new StringVendorExtension("ZhangXinWang", "https://gitee.com/zhangxinwang/blog"));
//        vendorExtensions.add(new StringVendorExtension("XiaQing", ""));
        return new ApiInfo("lucky cache项目接口 ",
                "单机版lucky项目,后面可能会删除",
                "1.0",
                "https://gitee.com/zhangxinwang/blog/blob/master/other/lucky-swagger-service.md",
                contact, "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                vendorExtensions);
    }

}
